home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 8
/
Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO
/
047a
/
lex_yacc.arj
/
FINDPROC.L
< prev
next >
Wrap
Text File
|
1989-05-28
|
3KB
|
104 lines
%{
(* Sample Lex program to search for function and procedure headers in
Pascal source files. *)
(* Name: findproc - search procedures and functions in Pascal source files
Synopsis: findproc <file-name-spec> [><output-file>]
Description: looks for lines starting with a procedure or function header
in the specified files (wildcards allowed; extension .pas must be given
explicitly); prints numbers and contents of the lines found; output may
also be redirected to <output-file>
Bugs: "function" and "procedure" keywords must either be in lower- or
uppercase (no mixed upper/lowercase); cannot handle nested comments
in Turbo Pascal style
*)
(* to compile this Lex program, issue the command `lex findproc' and then
`tpc findproc' *)
uses LexLib, DOS;
function yywrap : boolean; forward;
(* redefined for wrap around at endoffile *)
procedure scan_comment; forward;
(* skips a comment *)
%}
function function|FUNCTION
procedure procedure|PROCEDURE
%%
^[ \t]*({function}|{procedure})[ \t].*$
begin
writeln(yylineno:4, ': ', yytext);
reject
{ reject is needed to reprocess
any comments on the line }
end;
"(*" |
"{" scan_comment;
. |
\n ;
%%
var
search_rec : SearchRec; (* used to process wildcards *)
function path(filename : string) : string;
(* returns path contained in filename *)
var
i : integer;
begin
for i := length(filename) downto 1 do
if (filename[i]=':') or (filename[i]='\') then
begin
path := copy(filename, 1, i);
exit
end;
path := ''
end(*path*);
procedure openfile(name : string);
begin
writeln(name, ':');
assign(yyin, name);
reset(yyin);
yylineno := 1;
end(*openfile*);
function yywrap;
begin
close(yyin);
findNext(search_rec);
if DosError=0 then openfile(path(paramStr(1))+search_rec.name);
yywrap := DosError<>0
end(*yywrap*);
procedure scan_comment;
var c : char;
begin
repeat
case input of
'*': begin
c := input;
if c=')' then
exit
else
unput(c)
end;
'}': exit;
end
until false
end(*scan_comment*);
begin
findFirst(paramStr(1), 0, search_rec);
if DosError=0 then
begin
openfile(path(paramStr(1))+search_rec.name);
if yylex=0 then (* done *)
end
else
writeln('no files found')
end(*findproc*).